package com.qf.controller;

import com.qf.pojo.DtsAccountTrace;
import com.qf.service.DtsAccountTraceService;
import com.qf.util.JacksonUtil;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/admin/brokerage")
public class AdminBrokerageController {
    @Autowired
    private DtsAccountTraceService dtsAccountTraceService;

    //显示佣金列表--分页
    @GetMapping("/list")
    public Object list(int page,int limit,String sort,String order,int... statusArray){

        //获得佣金表集合  指定范围，页数以及每一页多少条
        List<DtsAccountTrace> dtsAccountTraces = dtsAccountTraceService.find(page, limit, sort, order,statusArray);
        //total总数
        Integer count = dtsAccountTraceService.count();
        Map<String,Object> result =new HashMap<>();

        result.put("total",count);
        result.put("traceList",dtsAccountTraces);
        return ResponseUtil.ok(result);

    }
    @RequestMapping("/approve")
    public Object approve(@RequestBody String body){
        Integer id = JacksonUtil.parseInteger(body, "id");
        Integer status = JacksonUtil.parseInteger(body, "status");
        String traceMsg = JacksonUtil.parseString(body, "traceMsg");
        //状态：通过是1，不通过是2
        //备注
        dtsAccountTraceService.approve(id,status,traceMsg);
        return ResponseUtil.ok();
    }

}
